package com.pansoft.kline.util;

import com.efounder.constant.EnvironmentVariable;
import com.pansoft.kline.greendao.DaoSessionUtil;
import com.pansoft.kline.greendao.SelfSelectedBeanDao;
import com.pansoft.kline.model.SelfSelectedBean;

import java.util.List;

/**
 * 自选相关
 */
public class SelfSelectUtils {



    /**
     * 是否已在自选里
     * @return 是，返回id，否，返回-1；
     */
    public static long getIsSelectedId(String marketId) {
        try {
            List<SelfSelectedBean> list = DaoSessionUtil.getInstance().getSelfSelectedBeanDao().queryBuilder().
                    where(SelfSelectedBeanDao.Properties.UserName.eq(EnvironmentVariable.getUserName())).list();

            for (int i = 0; i < list.size(); i++) {
                if (marketId.equals(list.get(i).getMarketId())) {
                    return list.get(i).getId();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }
}
